<div class="content-section introduction">
    <div>
        <span class="feature-title">ConfirmDialog</span>
        <span>ConfirmDialog is backed by a service utilizing Observables to display confirmation windows
            easily that can be shared by multiple actions on the same component.</span>
    </div>
</div>

<div class="content-section implementation">
    <p-growl [value]="msgs"></p-growl>
    
    <p-confirmDialog></p-confirmDialog>

    <button type="button" (click)="confirm1()" pButton icon="fa-check" label="Confirm"></button>
    
    <button type="button" (click)="confirm2()" pButton icon="fa-trash" label="Delete"></button>
</div>

<div class="content-section documentation">
    <p-tabView effect="fade">
        <p-tabPanel header="Documentation">
            <h3>Import</h3>
<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;ConfirmDialogModule,ConfirmationService&#125; from 'primeng/primeng';
</code>
</pre>

            <h3>Getting Started</h3>
            <p>ConfirmDialog is defined using p-confirmDialog tag and an instance of ConfirmationService is required to display it by 
                calling confirm method.</p>
                    
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-confirmDialog header="Confirmation" icon="fa fa-question-circle" width="425"&gt;&lt;/p-confirmDialog&gt;

&lt;button type="text" (click)="confirm()" pButton icon="fa-check" label="Confirm"&gt;&lt;/button&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
export class ConfirmDialogDemo &#123; 
           
    constructor(private confirmationService: ConfirmationService) &#123;&#125;

    confirm() &#123;
        this.confirmationService.confirm(&#123;
            message: 'Are you sure that you want to perform this action?',
            accept: () => &#123;
                //Actual logic to perform a confirmation
            &#125;
        &#125;);
    &#125;
&#125;
</code>
</pre>

            <p>Confirm method takes a confirmation instance used to customize the dialog UI along with accept and reject actions.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>message</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Message of the confirmation.</td>
                        </tr>
                        <tr>
                            <td>key</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Optional key to match the key of the confirm dialog, necessary to use when component tree has multiple confirm dialogs.</td>
                        </tr>
                        <tr>
                            <td>header</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Header text of the dialog.</td>
                        </tr>
                        <tr>
                            <td>icon</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Icon to display next to the message.</td>
                        </tr>
                        <tr>
                            <td>accept</td>
                            <td>Function</td>
                            <td>null</td>
                            <td>Callback to execute when action is confirmed.</td>
                        </tr>
                        <tr>
                            <td>reject</td>
                            <td>Function</td>
                            <td>null</td>
                            <td>Callback to execute when action is rejected.</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <h3>Customization</h3>
            <p>Properties of the dialog are defined in two ways, message, icon and header properties can either
            be defined using confirm method or declaratively on p-confirmDialog ng-template. If these values are unlikely to change then
            declarative approach would be useful, still properties defined in a ng-template can be overriden with confirm method call.</p>
            
            <p>In addition, buttons at footer section can be customized by passing your own UI, important note to make confirmation work with
            a custom UI is defining a local ng-template variable for the dialog and assign accept()-reject() methods to your own buttons.</p>

<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-confirmDialog header="Confirmation" icon="fa fa-question-circle" width="425" #cd&gt;
    &lt;p-footer&gt;
        &lt;button type="button" pButton icon="fa-close" label="No" (click)="cd.reject()"&gt;&lt;/button&gt;
        &lt;button type="button" pButton icon="fa-check" label="Yes" (click)="cd.accept()"&gt;&lt;/button&gt;
    &lt;/p-footer&gt;
&lt;/p-confirmDialog&gt;
</code>
</pre>

            <h3>Properties</h3>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                         <tr>
                            <td>header</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Title text of the dialog.</td>
                         </tr>
                         <tr>
                           <td>message</td>
                           <td>string</td>
                           <td>null</td>
                           <td>Message of the confirmation.</td>
                        </tr>
                        <tr>
                            <td>key</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Optional key to match the key of confirm object, necessary to use when component tree has multiple confirm dialogs.</td>
                        </tr>
                        <tr>
                          <td>icon</td>
                          <td>string</td>
                          <td>null</td>
                          <td>Icon to display next to message.</td>
                        </tr>
                        <tr>
                          <td>acceptLabel</td>
                          <td>string</td>
                          <td>Yes</td>
                          <td>Label of the accept button.</td>
                        </tr>
                        <tr>
                          <td>acceptIcon</td>
                          <td>string</td>
                          <td>fa-check</td>
                          <td>Icon of the accept button.</td>
                        </tr>
                        <tr>
                          <td>acceptVisible</td>
                          <td>boolean</td>
                          <td>true</td>
                          <td>Visibility of the accept button.</td>
                        </tr>
                        <tr>
                          <td>rejectLabel</td>
                          <td>string</td>
                          <td>No</td>
                          <td>Label of the reject button.</td>
                        </tr>
                        <tr>
                          <td>rejectIcon</td>
                          <td>string</td>
                          <td>fa-close</td>
                          <td>Icon of the reject button.</td>
                        </tr>
                        <tr>
                          <td>rejectVisible</td>
                          <td>boolean</td>
                          <td>true</td>
                          <td>Visibility of the reject button.</td>
                        </tr>
                        <tr>
                            <td>width</td>
                            <td>int</td>
                            <td>300</td>
                            <td>Width of the dialog.</td>
                        </tr>
                        <tr>
                            <td>height</td>
                            <td>int</td>
                            <td>auto</td>
                            <td>Height of the dialog.</td>
                        </tr>
                        <tr>
                            <td>closeOnEscape</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Specifices if pressing escape key should hide the dialog.</td>
                        </tr>
                        <tr>
                            <td>rtl</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When enabled dialog is displayed in RTL direction.</td>
                        </tr>
                        <tr>
                            <td>closable</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Adds a close icon to the header to hide the dialog.</td>
                        </tr>
                        <tr>
                            <td>responsive</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>In responsive mode, dialog adjusts itself to screen width.</td>
                        </tr>
                        <tr>
                            <td>appendTo</td>
                            <td>any</td>
                            <td>null</td>
                            <td>Target element to attach the dialog, valid values are "body" or a local ng-template variable of another element.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Styling</h3>
            <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Element</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>ui-dialog</td>
                            <td>Container element</td>
                        </tr>
                        <tr>
                            <td>ui-confirmdialog</td>
                            <td>Container element</td>
                        </tr>
                        <tr>
                            <td>ui-dialog-titlebar</td>
                            <td>Container of header.</td>
                        </tr>
                        <tr>
                            <td>ui-dialog-title</td>
                            <td>Header element.</td>
                        </tr>
                        <tr>
                            <td>ui-dialog-titlebar-icon</td>
                            <td>Icon container inside header.</td>
                        </tr>
                        <tr>
                            <td>ui-dialog-titlebar-close</td>
                            <td>Close icon element.</td>
                        </tr>
                        <tr>
                            <td>ui-dialog-content</td>
                            <td>Content element.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Dependencies</h3>
            <p>ConfirmationService</p>
        </p-tabPanel>

        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/confirmdialog" class="btn-viewsource" target="_blank">
                <i class="fa fa-github"></i>
                <span>View on GitHub</span>
            </a>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-growl [value]="msgs"&gt;&lt;/p-growl&gt;
    
&lt;p-confirmDialog&gt;&lt;/p-confirmDialog&gt;

&lt;button type="button" (click)="confirm1()" pButton icon="fa-check" label="Confirm"&gt;&lt;/button&gt;

&lt;button type="button" (click)="confirm2()" pButton icon="fa-trash" label="Delete"&gt;&lt;/button&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
@Component(&#123;
    templateUrl: 'showcase/demo/confirmdialog/confirmdialogdemo.html',
    providers: [ConfirmationService]
&#125;)
export class ConfirmDialogDemo &#123;
    
    msgs: Message[] = [];
    
    constructor(private confirmationService: ConfirmationService) &#123;&#125;

    confirm1() &#123;
        this.confirmationService.confirm(&#123;
            message: 'Are you sure that you want to proceed?',
            header: 'Confirmation',
            icon: 'fa fa-question-circle',
            accept: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Confirmed', detail:'You have accepted'&#125;];
            &#125;,
            reject: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Rejected', detail:'You have rejected'&#125;];
            &#125;
        &#125;);
    &#125;

    confirm2() &#123;
        this.confirmationService.confirm(&#123;
            message: 'Do you want to delete this record?',
            header: 'Delete Confirmation',
            icon: 'fa fa-trash',
            accept: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Confirmed', detail:'Record deleted'&#125;];
            &#125;,
            reject: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Rejected', detail:'You have rejected'&#125;];
            &#125;
        &#125;);
    &#125;
&#125;
</code>
</pre>
        </p-tabPanel>
    </p-tabView>
</div>
